package kr.hyunist.androidcomplete01saeildamil.ch08;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class TimerEx2 extends Activity {
	int value = 0;
	TextView tv;
	CountDownTimer mTimer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.timertest);
		
		tv = (TextView) findViewById(R.id.timertv);
		
		mTimer = new CountDownTimer(10 * 1000, 1000) {
			
			@Override
			public void onTick(long millisUntilFinished) {
				value++;
				tv.setText(value + "Seconds");
				/*if(value == 5){
					cancel();
				}*/
			}
			
			@Override
			public void onFinish() {
				
			}
		};
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.countdown, menu);
		
		return true;
	}
	
/*	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case R.id.countdownstart:
			mTimer.start();
			return true;
		
		case R.id.countdownstop:
			mTimer.cancel();
			return true;
		}
		
		return false;
	}*/
	
	public void mOnClick(MenuItem menu){
		switch(menu.getItemId()){
		case R.id.countdownstart:
			mTimer.start();
			break;
		
		case R.id.countdownstop:
			mTimer.cancel();
			break;
		
		}
	}
	
	/*public void mOnClick(View v){
		case R.id.timertestbtn1:
		mTimer.start();
		break;
	
	case R.id.timertestbtn2:
		mTimer.cancel();
		break;
	}*/
}
